<template>
  <div class="detail-action">
    <div class="state">
      <span class="iconfont icon-order-unpay"></span>
      <p>{{ orderStatus[order.orderState].label }}</p>
    </div>
    <div class="info">
      <p>订单编号：{{ order.id }}</p>
      <p>下单时间：{{ order.createTime }}</p>
    </div>
    <div class="btn">
      <!-- 待付款 -->
      <template v-if="order.orderState === 1">
        <el-button @click="$router.push('/member/pay?id=' + order.id)" type="primary">立即付款</el-button>
        <el-button type="default" @click="handlerCancel(order)">取消订单</el-button>
      </template>
      <!-- 待发货 -->
      <template v-if="order.orderState === 2">
        <el-button type="default" @click="$router.push(`/member/checkout?orderId=${order.id}`)">再次购买</el-button>
      </template>
      <!-- 待收货 -->
      <template v-if="order.orderState === 3">
        <el-button type="default" @click="handlerConfirmOrder">确认收货</el-button>
        <el-button type="default" @click="$router.push(`/member/checkout?orderId=${order.id}`)">再次购买</el-button>
      </template>
      <!-- 待评价 -->
      <template v-if="order.orderState === 4">
        <el-button type="default" @click="$router.push(`/member/checkout?orderId=${order.id}`)">再次购买</el-button>
        <el-button type="default">评价商品</el-button>
        <el-button type="default">申请售后</el-button>
      </template>
      <!-- 已完成 -->
      <template v-if="order.orderState === 5">
        <el-button type="default" @click="$router.push(`/member/checkout?orderId=${order.id}`)">再次购买</el-button>
        <el-button type="default">查看评价</el-button>
        <el-button type="default">申请售后</el-button>
      </template>
      <!-- 已取消 -->
    </div>
    <!-- 取消订单 -->
    <Teleport to="#model" >
      <OrderCancelCom ref="OrderCancel"></OrderCancelCom>
    </Teleport>
  </div>
</template>
<script setup>
import { orderStatus } from '@/api/constants';
import OrderCancelCom from './order-cancel'
import { useCancelOrder } from '../index';
import { confirmOrder } from '@/api/order'
import { ElMessage } from 'element-plus'
const props = defineProps({
  order: {
    type: Object,
    default: () => ({})
  }
})
const emit = defineEmits( ['getDetailOrder'])
const { OrderCancel, handlerCancel } = useCancelOrder()
// 确认收货
const handlerConfirmOrder = async () => {
  await confirmOrder( props.order.id)
  ElMessage.success('确认收货成功')
  emit('getDetailOrder')
}
</script>

<style lang="scss" scoped>
.detail-action {
  height: 180px;
  width: 100%;
  display: flex;
  align-items: center;

  .state {
    width: 220px;
    text-align: center;

    .iconfont {
      font-size: 40px;
      color: $xtxColor;
    }

    p {
      font-size: 16px;
      color: #666;
      margin-bottom: 10px;
    }
  }

  .info {
    width: 240px;
    line-height: 30px;

    p {
      color: #999;
    }
  }

  .btn {
    flex: 1;
    text-align: right;
    margin-right: 100px;

    .xtx-button {
      margin-left: 20px;
    }
  }
}
</style>